from rest_framework import serializers
from . import models

class CourseCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseCategory
        fields = ('name','id')

# 子序列化
class TeacherSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Teacher
        fields = ('name','role_name','title','signature','image','brief')


# 课程群查接口
class CourseSerializer(serializers.ModelSerializer):
    teacher = TeacherSerializer(many=False)
    class Meta:
        model = models.Course
        # fields = ('id','name','price','brief')
        fields = (
                  'id',
                  'name',
                  'course_img',
                  'brief',
                  'pub_sections',
                  'price',
                  'students',
                  'period',
                  'sections',
                  'course_type_name',
                  'level_name',
                  'status_name',
                  'teacher',
                  'section_list',

                  )


class CourseSectionSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseSection
        fields = ('name','orders','duration','free_trail','section_link')

class CourseChapterSerializer(serializers.ModelSerializer):
    coursesections = CourseSectionSerializer(many=True)
    class Meta:
        model = models.CourseChapter
        fields = ('name','chapter','summary','coursesections')
